﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using QUANLIHOCSINH.BussinessObject;
using QUANLIHOCSINH.BussinessLogic;
namespace QUANLIHOCSINH
{
    public partial class FrmThayDoiQuiDinh : Form
    {
        QUIDINHBUS quidinh = new QUIDINHBUS();
        public FrmThayDoiQuiDinh()
        {
            InitializeComponent();
        }

        private void btnSua_Click(object sender, EventArgs e)
        {
            EnableButton(true);
            
        }
        private void EnableButton(bool enable)
        {
            gbquidinh.Enabled = enable;
            btnCapNhat.Visible = enable;
            btnHuy.Visible = enable ;
            btnSua.Visible = !enable;
        }
        //Lay Thong Tin Dien Vao Tu Text box
        private QUIDINH LayThongTinQuiDinh()
        {
            QUIDINH hs = new QUIDINH();
            hs.SiSo = txtSiSo.Text;
            hs.SoMon = txtSoMon.Text;
            hs.SoTiet = txtSoTiet.Text;
            hs.DoTuoiTren = txtTuoiDuoi.Text;
            hs.DoTuoiDuoi = txtTuoiTren.Text;
            return hs;
        }
        //TIen hanh cap nhat qui dinh
        private void btnCapNhat_Click(object sender, EventArgs e)
        {
            if (quidinh.SuaQuiDinh(LayThongTinQuiDinh()) == true)
            {
                Utility.quidinh.SiSo = txtSiSo.Text;
                Utility.quidinh.SoMon = txtSoMon.Text;
                Utility.quidinh.SoTiet = txtSoTiet.Text;
                Utility.quidinh.DoTuoiDuoi = txtTuoiDuoi.Text;
                Utility.quidinh.DoTuoiTren = txtTuoiTren.Text;
            }
            else
            {
                MessageBox.Show("That Bai");
            }
        }

        private void btnHuy_Click(object sender, EventArgs e)
        {
            EnableButton(false);
        }

        //Load qui dinh
        private void FrmThayDoiQuiDinh_Load(object sender, EventArgs e)
        {
            txtSoMon.Text = Utility.quidinh.SoMon;
            txtSiSo.Text = Utility.quidinh.SiSo;
            txtTuoiDuoi.Text = Utility.quidinh.DoTuoiDuoi;
            txtTuoiTren.Text = Utility.quidinh.DoTuoiTren;
            txtSoTiet.Text = Utility.quidinh.SoTiet;
            EnableButton(false);
        }
    }
}
